/* eslint-disable array-callback-return */
/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { message } from 'antd';
import { isLegalData } from '@/utils/utils';
import {
  getPostList,
  getAreaList,
  getBrandsList,
  getPies,
  storageSummary,
  storagePic,
  smsSummary,
  orderSummary,
  orderPic,
  storageList,
  storageSum,
  smsSum,
  smsList,
  orderSum,
  orderList,
  dakFansSummaryStat,
  dakFansEverydayStat,
  fansSummary,
  inStorageRate,
  outStorageRate,
  eachWeekComplaintRate,
  yesterdaData,
  getHistogram,
  outStorageRateList,
  rankDetailList,
} from '../services/api';

const noop = () => {};

export default {
  namespace: 'list',

  state: {
    list: null,
    pagination: null,
    brandList: null,
    summary: null,
    summary_detail: null,
    summary_brand: null,
    sumsms_detail: null,
    sumorder_detail: null,
    sumorder_brand: null,
    in_sum: null,
    out_sum: null,
    back_sum: null,
    sms_sum: null,
    order_sum: null,
    order_realnum_sum: null,
    all_total_detail: null,
    canvesList: [],
    smsSummary: [],
    orderSummary: [],
    fansSummary: [],
    complaintRateList: [],
    inStorageRateList: [],
    outStorageRateList: [],
    outStorageRateTableList: {
      list: [],
      pagination: {},
    },
    piesList: [],
    outPic: [],
    orderPic: [],
    orderPicName: [],
    storagePic: [],
    storageSummary: [],
    inout: {
      list: [],
      pagination: {},
    },
    inout_detail: {
      list: null,
      pagination: null,
    },
    inout_brand: {
      list: null,
      pagination: null,
    },
    sms: {
      list: null,
      pagination: null,
    },
    sms_datail: {
      list: null,
      pagination: null,
    },
    order: {
      list: [],
      pagination: {},
    },
    order_datail: {
      list: null,
      pagination: null,
    },
    order_brand: {
      list: null,
      pagination: null,
    },
    fans: {
      list: [],
      pagination: {},
    },
    fans_datail: {
      list: null,
      pagination: null,
    },
    // 数据统计通用的搜索栏数据
    searchFormValues: {},
    overviewData: {},
    // H5数据总览
    inOutNumber: [],
    sendAndRate: [],
    stationAndFans: [],
    inNumRank: [],
    outRateRank: [],

    // 地址的缓存数据
    address_options: [],
    yesterdaData: [{}],
    brandPieList: [],
    inBrandPieList: [],
    outBrandPieList: [],
    orderBrandPieList: [],
    regionalRanking: [],
    areaInNumRank: [], // 区域排名的入库数排名数据
    outNumRank: [],
    areaOutRateRank: [], // 区域排名的出库率排名数据
    orderNumRank: [],
    fansNumRank: [],
    inNumDetailList: {
      list: [],
      pagination: null,
      summary: {},
    },
    outRateDetailList: {
      list: [],
      pagination: null,
    },
    sendOrderDetailList: {
      list: [],
      pagination: null,
      summary: {},
    },
    fansDetailList: {
      list: [],
      pagination: null,
      summary: {},
    },
    // listType: "inNumDetailList",
  },

  effects: {
    *getPostList({ payload }, { call, put }) {
      const response = yield call(getPostList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { result, count, page, page_num, in_num_sum, out_num_sum, back_num_sum } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            list: result,
            pagination: {
              count,
              pageSize: page_num,
              current: page,
              summary: {
                in_num_sum,
                out_num_sum,
                back_num_sum,
              },
            },
          },
        });
      } else {
        yield put({
          type: 'save',
          payload: {
            list: result,
            pagination: {
              total: 0,
              pageSize: 0,
              current: page,
              summary: null,
            },
          },
        });
        message.error(msg);
      }
    },
    *getAreaList({ payload, then = noop }, { call, put }) {
      const response = yield call(getAreaList, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            areaList: data,
          },
        });
        then(data);
      }
    },
    *getBrandsList({ payload, then = noop }, { call, put, select }) {
      const { brandList } = yield select(_ => _.list);
      if (brandList && brandList.length > 0) {
        return;
      }
      const response = yield call(getBrandsList, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            brandList: data,
          },
        });
      } else {
        yield put({
          type: 'save',
          payload: {
            brandList: [],
          },
        });
      }
      then(data);
    },
    *getPies({ payload, then = noop }, { call }) {
      const response = yield call(getPies, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        then(isLegalData(data, []));
      }
    },
    // 获取昨日数据总览
    *yesterdaData({ payload, then = noop }, { call, put }) {
      const response = yield call(yesterdaData, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            yesterdaData: [isLegalData(data, {})],
            overviewData: data,
            inOutNumber: [
              {
                name: '入库数',
                value: data.in_num || 0,
              },
              {
                name: '出库数',
                value: data.out_num || 0,
              },
              {
                name: '退回数',
                value: data.back_num || 0,
              },
              {
                name: '短信数',
                value: data.sms_num || 0,
              },
            ],
            sendAndRate: [
              {
                name: '寄件数',
                value: data.order_num || 0,
              },
              {
                name: '快递费',
                value: data.fee_num || 0,
              },
              {
                name: '出库率',
                value: `${data.out_rate}%` || 0,
              },
              {
                name: '投诉率',
                value: `${data.complaint_rate}‱` || 0,
              },
            ],
            stationAndFans: [
              {
                name: '新增站点',
                value: data.station_num || 0,
              },
              {
                name: '累计站点',
                value: data.total_station_num || 0,
              },
              {
                name: '新增粉丝',
                value: data.fans_num || 0,
              },
              {
                name: '累计粉丝',
                value: data.total_fans_num || 0,
              },
            ],
          },
        });
        then([isLegalData(data, {})]);
      }
    },
    // 个人，获取昨日数据总览
    *yzYesterdayData({ payload, then = noop }, { call, put }) {
      const response = yield call(yesterdaData, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        const averageSmsFee = ((data.sms_fee / data.sms_num) * 100).toFixed(1) * 1;
        yield put({
          type: 'save',
          payload: {
            yesterdaData: [isLegalData(data, {})],
            overviewData: data,
            inOutNumber: [
              {
                name: '入库数',
                value: data.in_num || 0,
              },
              {
                name: '出库数',
                value: data.out_num || 0,
              },
              {
                name: '通知费用',
                value: data.sms_fee || 0,
                sub:
                  averageSmsFee <= 3.8
                    ? averageSmsFee >= 1
                      ? `平均每条${averageSmsFee}分`
                      : '平均每条低于1分'
                    : '',
              },
              {
                name: '通知数量',
                value: data.sms_num || 0,
                question:
                  data.split_num * 1 >= 20
                    ? '该驿站有部分短信超70字符，拆分为多条短信发送，为节省短信费用，请精简短信模板、驿站地址'
                    : '',
              },
            ],
            sendAndRate: [
              {
                name: '寄件数',
                value: data.order_num || 0,
              },
              {
                name: '快递费',
                value: data.fee_num || 0,
              },
              {
                name: '出库率',
                value: `${data.out_rate}%` || 0,
              },
              {
                name: '投诉率',
                value: `${data.complaint_rate}‱` || 0,
              },
            ],
          },
        });
        then([isLegalData(data, {})]);
      }
    },
    // 出库折线
    *storageSummary({ payload, then = noop }, { call, put }) {
      const response = yield call(storageSummary, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            canvesList: isLegalData(data, []),
          },
        });
        then(isLegalData(data, []));
      }
    },
    // 品牌占比
    *brandPie({ payload }, { call, put }) {
      const { type } = payload;
      const response = yield call(storagePic, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        switch (type) {
          case 'in':
            yield put({
              type: 'save',
              payload: {
                inBrandPieList: isLegalData(data, []),
              },
            });
            break;
          case 'out':
            yield put({
              type: 'save',
              payload: {
                outBrandPieList: isLegalData(data, []),
              },
            });
            break;
          case 'order':
            yield put({
              type: 'save',
              payload: {
                orderBrandPieList: isLegalData(data, []),
              },
            });
            break;
          default:
            yield put({
              type: 'save',
              payload: {
                brandPieList: isLegalData(data, []),
              },
            });
            break;
        }
      }
    },
    // 品牌占比
    *storagePic({ payload }, { call, put }) {
      const response = yield call(storagePic, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            piesList: isLegalData(data, []),
            storagePic: isLegalData(data, []),
          },
        });
      }
    },
    // 出库拼图
    *outPic({ payload }, { call, put }) {
      const response = yield call(storagePic, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            outPic: isLegalData(data, []),
          },
        });
      }
    },
    // 柱状图，入库数
    *regionalRanking({ payload }, { call, put }) {
      const { type = '', formListType } = payload;
      const reqDate = { ...payload };
      delete reqDate.formListType;
      const response = yield call(getHistogram, reqDate);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        switch (type) {
          case 'in': // 入库数排名
            if (formListType == 'areaRanking') {
              // 防止影响总览的数据
              yield put({
                type: 'save',
                payload: {
                  areaInNumRank: isLegalData(data, []),
                },
              });
            } else {
              yield put({
                type: 'save',
                payload: {
                  inNumRank: isLegalData(data, []),
                },
              });
            }
            break;
          case 'out': // 出库数排名
            yield put({
              type: 'save',
              payload: {
                outNumRank: isLegalData(data, []),
              },
            });
            break;
          case 'out_rate': // 出库率排名
            if (formListType == 'areaRanking') {
              // 防止影响总览的数据
              yield put({
                type: 'save',
                payload: {
                  areaOutRateRank: isLegalData(data, []),
                },
              });
            } else {
              yield put({
                type: 'save',
                payload: {
                  outRateRank: isLegalData(data, []),
                },
              });
            }
            break;
          case 'order': // 寄件订单数排名
            yield put({
              type: 'save',
              payload: {
                orderNumRank: isLegalData(data, []),
              },
            });
            break;
          case 'fans': // 公众号粉丝数排名
            yield put({
              type: 'save',
              payload: {
                fansNumRank: isLegalData(data, []),
              },
            });
            break;
          default:
            yield put({
              type: 'save',
              payload: {
                regionalRanking: isLegalData(data, []),
              },
            });
            break;
        }
      }
    },
    // 短信折线
    *smsSummary({ payload }, { call, put }) {
      const response = yield call(smsSummary, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            smsSummary: isLegalData(data, []),
          },
        });
      }
    },
    // 三十日入库率，三日出库率
    *storageRate({ payload }, { call, put }) {
      const inResponse = yield call(inStorageRate, payload);
      const outResponse = yield call(outStorageRate, payload); // 三日出库率
      if (!inResponse || !outResponse) return;
      const { code, data } = inResponse;
      const { code: _code, data: _data } = outResponse;
      isLegalData(data, []).map(val => {
        val.inStorageRate = val.rate;
      });
      isLegalData(_data, []).map(val => {
        val.outStorageRate = val.rate;
      });
      if (code == 0 && _code == 0 && data && _data) {
        yield put({
          type: 'save',
          payload: {
            inStorageRateList: isLegalData(data, []),
            outStorageRateList: isLegalData(_data, []),
          },
        });
      }
    },
    // 三日出库率列表
    *outStorageRateTableList({ payload }, { call, put }) {
      const response = yield call(outStorageRateList, payload); // 三日出库率
      if (!response) return;
      const { code, data } = response;
      const { list, page, pageSize, total } = data;

      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            outStorageRateTableList: {
              list: isLegalData(list, []),
              pagination: {
                total,
                pageSize,
                current: page,
              },
            },
          },
        });
      }
    },
    // 每周投诉率
    *complaintRate({ payload }, { call, put }) {
      const response = yield call(eachWeekComplaintRate, payload);
      if (!response) return;
      const { code, data } = response;
      isLegalData(data, []).map(val => {
        val.complaintRate = val.rate;
      });
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            complaintRateList: isLegalData(data, []),
          },
        });
      }
    },
    // 出库汇总列表
    *storageSum({ payload }, { call, put }) {
      const response = yield call(storageSum, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { count, page, page_num, in_num_sum, out_num_sum, back_num_sum } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            inout: {
              list: data.data,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: {
                  in_num_sum,
                  out_num_sum,
                  back_num_sum,
                },
              },
            },
          },
        });
        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        yield put({
          type: 'save',
          payload: {
            inout: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 出库详情列表
    *storageList({ payload }, { call, put }) {
      const response = yield call(storageList, payload);
      if (!response) return;
      const { type } = payload;
      const { code, data, msg } = response;
      const { count, page, page_num, in_num_sum, out_num_sum, back_num_sum } = data;
      if (code == 0 && data) {
        if (type) {
          yield put({
            type: 'save',
            payload: {
              inout_brand: {
                list: data.data,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  summary_brand: {
                    brand_in_sum: in_num_sum,
                    brand_out_sum: out_num_sum,
                    brand_back_sum: back_num_sum,
                  },
                },
              },
            },
          });
        } else {
          yield put({
            type: 'save',
            payload: {
              inout_detail: {
                list: data.data,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  summary_detail: {
                    in_sum: in_num_sum,
                    out_sum: out_num_sum,
                    back_sum: back_num_sum,
                  },
                },
              },
            },
          });
        }

        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        if (type) {
          yield put({
            type: 'save',
            payload: {
              inout_brand: {
                list: null,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  summary_brand: null,
                },
              },
            },
          });
        } else {
          yield put({
            type: 'save',
            payload: {
              inout_detail: {
                list: null,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  summary_detail: null,
                },
              },
            },
          });
        }

        message.error(msg);
      }
    },
    // 短信汇总列表
    *smsSum({ payload }, { call, put }) {
      const response = yield call(smsSum, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { count, page, page_num, sum, wx_sum } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            sms: {
              list: data.data,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: {
                  sum,
                  wx_total: wx_sum,
                },
              },
            },
          },
        });
        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        yield put({
          type: 'save',
          payload: {
            sms: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 短信详情列表
    *smsList({ payload }, { call, put }) {
      const response = yield call(smsList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { count, page, page_num, sum } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            sms_datail: {
              list: data.data,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                sumsms_detail: {
                  sms_sum: sum,
                },
              },
            },
          },
        });
        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        yield put({
          type: 'save',
          payload: {
            sms_datail: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                sumsms_detail: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 订单汇总列表
    *orderSum({ payload }, { call, put }) {
      const response = yield call(orderSum, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { count, page, page_num, num_sum, realnum_sum } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            order: {
              list: data.data,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: {
                  num_sum,
                  realnum_sum,
                },
              },
            },
          },
        });
        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        yield put({
          type: 'save',
          payload: {
            order: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 订单详情列表
    *orderList({ payload }, { call, put }) {
      const response = yield call(orderList, payload);
      const { brand } = payload;
      if (!response) return;
      const { code, data, msg } = response;
      const { count, page, page_num, num_sum, realnum_sum } = data;
      if (code == 0 && data) {
        if (brand) {
          yield put({
            type: 'save',
            payload: {
              order_brand: {
                list: data.data,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  sumorder_brand: {
                    brand_order_sum: num_sum,
                    brand_order_realnum_sum: realnum_sum,
                  },
                },
              },
            },
          });
        } else {
          yield put({
            type: 'save',
            payload: {
              order_datail: {
                list: data.data,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  sumorder_detail: {
                    order_sum: num_sum,
                    order_realnum_sum: realnum_sum,
                  },
                },
              },
            },
          });
        }
        if (data.data.length == 0) {
          message.error('暂无数据');
        }
      } else {
        if (brand) {
          yield put({
            type: 'save',
            payload: {
              order_brand: {
                list: null,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  sumorder_brand: null,
                },
              },
            },
          });
        } else {
          yield put({
            type: 'save',
            payload: {
              order_datail: {
                list: data.data,
                pagination: {
                  total: count,
                  pageSize: page_num,
                  current: page,
                  sumorder_detail: null,
                },
              },
            },
          });
        }

        message.error(msg);
      }
    },
    // 订单折线
    *orderSummary({ payload, then = noop }, { call, put }) {
      const response = yield call(orderSummary, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            orderSummary: isLegalData(data, []),
          },
        });
        then(isLegalData(data, []));
      }
    },
    // 订单拼图
    *orderPic({ payload }, { call, put }) {
      const response = yield call(orderPic, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            orderPic: isLegalData(data, []),
          },
        });
      }
    },
    // 订单实名拼图
    *orderPicName({ payload }, { call, put }) {
      const response = yield call(orderPic, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            orderPicName: isLegalData(data, []),
          },
        });
      }
    },
    // 粉丝汇总列表
    *dakFansSummaryStat({ payload }, { call, put }) {
      const response = yield call(dakFansSummaryStat, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { every, count, page, page_num, all_total } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            fans: {
              list: every,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                all_total,
              },
            },
          },
        });
        if (every.length == 0) {
          message.error('暂无数据');
        }
      } else {
        yield put({
          type: 'save',
          payload: {
            fans: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                summary: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 粉丝详情列表
    *dakFansEverydayStat({ payload, then = noop }, { call, put }) {
      const response = yield call(dakFansEverydayStat, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { every, count, page, page_num, all_total } = data;
      const { new_add, total } = all_total;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            fans_datail: {
              list: every,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                all_total_detail: {
                  fans_add: new_add,
                  fans_total: total,
                },
              },
            },
          },
        });
        if (every.length == 0) {
          message.error('暂无数据');
        }
        then(every);
      } else {
        yield put({
          type: 'save',
          payload: {
            fans_datail: {
              list: null,
              pagination: {
                total: count,
                pageSize: page_num,
                current: page,
                all_total_detail: null,
              },
            },
          },
        });
        message.error(msg);
      }
    },
    // 粉丝折线
    *fansSummary({ payload, then = noop }, { call, put }) {
      const response = yield call(fansSummary, payload);
      if (!response) return;
      const { code, data } = response;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            fansSummary: isLegalData(data, []),
          },
        });
        then(isLegalData(data, []));
      }
    },
    // 下属驿站搜索框数据缓存
    *setFormValues({ payload }, { put, select }) {
      const { searchFormValues } = yield select(_ => _.list);
      const { listType, init_branch = [], areaRankingListType, page = 1 } = payload;
      const formType = areaRankingListType || listType;
      const date = payload[`${formType}Date`];
      const siteId = payload[`${formType}SiteId`];
      const addressId = payload[`${formType}AddressId`];
      const brandId = payload[`${formType}BrandId`];
      yield put({
        type: 'save',
        payload: {
          searchFormValues: {
            ...searchFormValues,
            [`${formType}Date`]: date,
            [`${formType}SiteId`]: siteId,
            [`${formType}AddressId`]: addressId,
            [`${formType}BrandId`]: brandId,
            page,
            init_branch,
            listType: formType,
          },
        },
      });
    },
    // 区域排名，入库数明细列表
    *inNumDetailList({ payload }, { call, put }) {
      const response = yield call(rankDetailList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { total, page, storage_total, out_total, back_total, list = [] } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            inNumDetailList: {
              list: isLegalData(list, []),
              pagination: {
                total,
                pageSize: 20,
                current: page,
                showQuickJumper: false,
                showSizeChanger: false,
              },
              summary: {
                storage_total,
                out_total,
                back_total,
              },
            },
          },
        });
        if (isLegalData(list, []).length == 0) {
          message.error('暂无明细数据');
        }
      } else {
        message.error(msg);
      }
    },
    // 区域排名，出库率明细列表
    *outRateDetailList({ payload }, { call, put }) {
      const response = yield call(rankDetailList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { total, page, list = [] } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            outRateDetailList: {
              list: isLegalData(list, []),
              pagination: {
                total,
                pageSize: 20,
                current: page,
                showQuickJumper: false,
                showSizeChanger: false,
              },
            },
          },
        });
        if (isLegalData(list, []).length == 0) {
          message.error('暂无明细数据');
        }
      } else {
        message.error(msg);
      }
    },
    // 区域排名，寄件订单明细列表
    *sendOrderDetailList({ payload }, { call, put }) {
      const response = yield call(rankDetailList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { total, page, list = [], total_order_num, total_real_order_num, total_fee_num } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            sendOrderDetailList: {
              list: isLegalData(list, []),
              pagination: {
                total,
                pageSize: 20,
                current: page,
                showQuickJumper: false,
                showSizeChanger: false,
              },
              summary: {
                total_order_num,
                total_real_order_num,
                total_fee_num,
              },
            },
          },
        });
        if (isLegalData(list, []).length == 0) {
          message.error('暂无明细数据');
        }
      } else {
        message.error(msg);
      }
    },
    // 区域排名，公众号粉丝明细列表
    *fansDetailList({ payload }, { call, put }) {
      const response = yield call(rankDetailList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { total, page, list = [], total_fans, total_new_fans } = data;
      if (code == 0 && data) {
        yield put({
          type: 'save',
          payload: {
            fansDetailList: {
              list: isLegalData(list, []),
              pagination: {
                total,
                pageSize: 20,
                current: page,
                showQuickJumper: false,
                showSizeChanger: false,
              },
              summary: {
                total_fans,
                total_new_fans,
              },
            },
          },
        });
        if (isLegalData(list, []).length == 0) {
          message.error('暂无明细数据');
        }
      } else {
        message.error(msg);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
